home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / LENSV10.ZIP / LENS.ASM next >
Encoding:
Assembly Source File  |  1994-08-19  |  7.6 KB  |  393 lines

  1. ;-----------------------------------------------------------------------;
  2. ; Lens effect                                ;
  3. ; Code by Nagy Daniel                            ;
  4. ;                                    ;
  5. ; On my VGA it's absolute flicker free! (Hope on yours too...)        ;
  6. ; It's a bit lame, so simplify it if you can.                ;
  7. ;                                    ;
  8. ; If you want to resize the lens, just calculate another transfrm.dat,    ;
  9. ; and correct xsize                            ;
  10. ;                                    ;
  11. ; Compile: TASM /m9                            ;
  12. ; Link:    TLINK /3                            ;
  13. ;                                    ;
  14. ;    Send ideas, comments to: rocker@hal2000.hal.vein.hu        ;
  15. ;-----------------------------------------------------------------------;
  16.  
  17.  
  18. DOSSEG
  19. .MODEL SMALL
  20. .STACK 200h
  21. .CODE
  22. .386
  23.  
  24. ASSUME CS:@CODE, DS:@CODE
  25.  
  26. xsize    equ    52        ;lens diameter
  27. xsize2    equ    xsize*xsize
  28.  
  29.  
  30. start:    push    cs
  31.     pop    ds
  32.     cld
  33.  
  34. ;--------------------- CPU check -----------------------
  35.     xor    ax,ax
  36.     push    ax
  37.     popf
  38.     pushf
  39.     pop    ax
  40.     and    ax,0f000h
  41.     cmp    ax,0f000h
  42.     je    no386
  43.     mov    ax,07000h
  44.     push    ax
  45.     popf
  46.     pushf
  47.     pop    ax
  48.     and    ax,07000h
  49.     jne    vgachk
  50. no386:    mov    ah,9
  51.     lea    dx,_386err
  52.     int    21h
  53.     jmp    errend
  54.  
  55. ;---------------------- VGA check ---------------------
  56. vgachk:    mov    ax,1a00h
  57.     int    10h
  58.     and    al,8
  59.     jnz    mouchk
  60.     mov    ah,9
  61.     lea    dx,vgaerr
  62.     int    21h
  63.     jmp    errend
  64.  
  65. ;--------------------- Mouse check --------------------
  66. mouchk:    mov    ax,0
  67.     int    33h
  68.     or    ax,ax
  69.     jnz    memchk
  70.     mov    ah,9
  71.     lea    dx,mouserr
  72.     int    21h
  73.     jmp    errend
  74.  
  75. ;--------------------- Memory check --------------------
  76. memchk:    mov    ebx,0a000h
  77.     mov    ax,ss
  78.     add    ax,32
  79.     sub    bx,ax
  80.     shl    ebx,4
  81.     cmp    ebx,64000
  82.     ja    ok2run
  83.     mov    ah,9
  84.     lea    dx,memerr
  85.     int    21h
  86.     jmp    errend
  87.  
  88. ;==================== Everything seems OK, let's start ====================
  89. ok2run:    mov    ax,0013h
  90.     int    10h        ;320x200x256 VGA mode
  91.  
  92.     mov    ax,7
  93.     xor    cx,cx
  94.     mov    dx,320-xsize
  95.     int    33h        ;define horizontal mouse range
  96.     inc    ax
  97.     mov    dx,200-xsize
  98.     int    33h        ;define vertical mouse range
  99.     
  100.     mov    [inpseg],0a000h
  101.     call    loadtga        ;import picture to screen
  102.     cmp    ah,1        ;error check
  103.     jnz    goon1
  104.     mov    ax,0003h
  105.     int    10h
  106.     mov    ah,9
  107.     lea    dx,filerr
  108.     int    21h
  109.     jmp    errend
  110.  
  111. goon1:    mov    ax,ss
  112.     add    ax,32
  113.     mov    [inpseg],ax
  114.     call    loadtga        ;import picture to memory
  115.     cmp    ah,1        ;error check
  116.     jnz    goon2
  117.     mov    ax,0003h
  118.     int    10h
  119.     mov    ah,9
  120.     lea    dx,filerr
  121.     int    21h
  122.     jmp    errend
  123.  
  124. goon2:    mov    ax,4
  125.     mov    cx,150
  126.     mov    dx,80
  127.     int    33h        ;center mouse cursor
  128.     mov    ax,3
  129.     int    33h        ;get mouse position and button status
  130.     mov    bx,dx
  131.     mov    ax,320
  132.     mul    bx
  133.     add    ax,cx        ;calculate cursor address
  134.     mov    [maddr],ax    ;and store mouse cursor address
  135.     mov    [mnewaddr],ax    ;and store mouse cursor address
  136.  
  137.  
  138.     call    getorig        ;get original picture
  139.     call    transf        ;make transformation
  140.     call    or2te        ;copy it to 'temp' buffer
  141.     lea    si,cs:dest    ;ds:si = stored original picture address
  142.     call    putimg        ;display transformed picture
  143.  
  144. ;================================ Main loop ==================================
  145. again:    mov    ax,000bh
  146.     int    33h        ;examine mouse movement
  147.     or    cx,cx
  148.     jnz    newpic        ;horizontal movement -> new picture
  149.     or    dx,dx
  150.     jnz    newpic        ;vertical movement -> new picture
  151.     mov    ax,3
  152.     int    33h        ;read mouse button status
  153.     and    bx,1
  154.     jnz    finish        ;quit if button pressed
  155.     mov    ah,1
  156.     int    16h        ;quit if key pressed
  157.     jnz    finis    
  158.     jmp    again        ;jump back
  159.  
  160. ;====================== Draw new picture if mouse moved ======================
  161. newpic:    mov    ax,3
  162.     int    33h        ;get new mouse position
  163.     mov    bx,dx
  164.     mov    ax,320
  165.     mul    bx
  166.     add    ax,cx        ;calculate cursor address
  167.     mov    cs:[mnewaddr],ax;and store mouse cursor address
  168.  
  169.     call    getorig        ;get original picture
  170.     call    transf        ;make transformation
  171.     call    vrtchk        ;VRT check
  172.     lea    si,cs:temp
  173.     call    putimg        ;display original picture from 'temp'
  174.     push    [cs:mnewaddr]
  175.     pop    [cs:maddr]
  176.     lea    si,cs:dest    ;ds:si = stored original picture address
  177.     call    putimg        ;display transformed picture
  178.     call    or2te        ;copy 'orig' to 'temp'
  179.  
  180.     jmp    again        ;jump back
  181.  
  182. ;============================== Quit program =================================
  183. finis:    xor    ah,ah
  184.     int    16h
  185. finish:    mov    ax,0
  186.     int    33h
  187.     mov    ax,0003h
  188.     int    10h
  189.  
  190. errend:    mov    ax,4c00h
  191.     int    21h
  192.  
  193.  
  194. ;=============================================================================
  195. ;=============================   Subroutines   ===============================
  196. ;=============================================================================
  197.  
  198. ;=============== Get original picture ============
  199. getorig    proc    near
  200.  
  201.     mov    si,cs:[mnewaddr];ds:si = mouse position address
  202.     push    [inpseg]    ;which is the upper-left corner
  203.     pop    ds        ;of the transformation area
  204.     push    cs
  205.     pop    es
  206.     lea    di,cs:orig
  207.     mov    cx,xsize    ;rows
  208.  
  209. ujra:    push    cx
  210.     mov    cx,xsize/4    ;columns
  211.     rep    movsd        ;store a row
  212.     pop    cx
  213.     add    si,320-xsize    ;jump to next row
  214.     loop    ujra        ;store all rows
  215.     ret
  216.  
  217.     endp    getorig
  218.  
  219. ;==================== Orig to Temp =====================
  220. or2te    proc    near
  221.  
  222.     mov    ax,cs
  223.     mov    ds,ax
  224.     mov    es,ax
  225.     lea    si,orig
  226.     lea    di,temp
  227.     mov    cx,676
  228.     rep    movsd
  229.     ret
  230.  
  231.     endp    or2te
  232.  
  233. ;======================= Put image ==========================
  234. ;si = buffer address to display
  235. putimg    proc    near
  236.  
  237.     push    cs
  238.     pop    ds
  239.     push    0a000h
  240.     pop    es
  241.     mov    di,[maddr]    ;es:di = address to put picture
  242.     mov    cx,xsize    ;rows
  243.  
  244. kovsr:    push    cx
  245.     mov    cx,xsize/4    ;columns
  246.     rep    movsd        ;display a row
  247.     pop    cx
  248.     add    di,320-xsize    ;go to next row
  249.     loop    kovsr        ;display all rows
  250.     ret
  251.  
  252.     endp    putimg
  253.  
  254. ;====================== Transformation =======================
  255. transf    proc    near
  256.  
  257.     push    cs
  258.     pop    ds
  259.     lea    bx,trans    ;bx = transformation array address
  260.     lea    bp,orig        ;bp = stored original picture address
  261.     lea    di,dest        ;di = transformed picture address
  262.     mov    cx,xsize2    ;transform all points
  263.  
  264. newpix:    mov    si,[bx]        ;si = pointer to needed pixel
  265.     add    si,bp
  266.     dec    si
  267.     movsb
  268.     inc    bx
  269.     inc    bx        ;next pixel
  270.     loop    newpix        ;transform all 961 pixels
  271.     ret
  272.  
  273.     endp    transf
  274.  
  275. ;========================= VRT Check =======================
  276. vrtchk    proc    near
  277.  
  278.     mov    dx,3dah
  279. z1:    in    al,dx        ;Is it Vertical Retrace?
  280.     test    al,8
  281.     jnz    z1        ;If yes, wait
  282.  
  283. z2:    in    al,dx        ;Is it Vertical Retrace?
  284.     test    al,8
  285.     jz    z2        ;If no, wait
  286.     ret
  287.  
  288.     endp    vrtchk
  289.  
  290. ;======================== Load TGA pix =========================
  291. loadtga    proc    near
  292.  
  293.     push    ds
  294.     push    cs
  295.     pop    ds
  296.     mov    ax,3D00h
  297.     lea    dx,TGA_filename
  298.     int 21h                ;open file
  299.     jc    errfil
  300.     mov    [TGA_handle],ax
  301.  
  302.     mov    ah,3Fh
  303.     mov    bx,[TGA_handle]
  304.     mov    cx,18            ;read crap
  305.     lea    dx,ReadBuffer
  306.     int    21h
  307.     jc    errfil
  308.         
  309.     mov    ah,3Fh
  310.     mov    bx,[TGA_handle]
  311.     mov    cx,768            ;read palette
  312.     lea    dx,ReadBuffer
  313.     int    21h
  314.     jc    errfil
  315.  
  316.     mov    cx,256
  317.     push    cs
  318.     pop    es
  319.     lea    si,ReadBuffer
  320.     lea    di,ReadBuffer
  321.  
  322. palfix:    lodsb
  323.     shr    al,2
  324.     mov    ah,al
  325.     lodsb
  326.     shr    al,2
  327.     mov    bh,al
  328.     lodsb
  329.     shr    al,2
  330.     stosb
  331.     mov    al,bh
  332.     stosb
  333.     mov    al,ah
  334.     stosb
  335.     dec    cx
  336.     jnz    palfix
  337.  
  338.     mov    ax,1012h
  339.     xor    bx,bx
  340.     mov    cx,256
  341.     push    cs
  342.     pop    es
  343.         lea    dx,ReadBuffer
  344.     int    10h            ;set all palette
  345.  
  346.     mov    ah,3Fh
  347.     mov    bx,[TGA_handle]
  348.     mov    cx,64000
  349.     push    [inpseg]
  350.     pop    ds
  351.     xor    dx,dx
  352.     int    21h            ;load picture
  353.     jc    errfil
  354.  
  355.     mov    ah,3Eh
  356.     mov    bx,[TGA_handle]
  357.     int    21h            ;close file
  358.     xor    ah,ah
  359.     jmp    fileok
  360.  
  361. errfil:    mov    ah,01h
  362. fileok:    pop    ds
  363.     ret
  364.  
  365.     endp    loadtga
  366.  
  367. ;=============================================================================
  368. ;========================      Data area        ==========================
  369. ;=============================================================================
  370.  
  371. mouserr    db    'Mouse driver not found','$'
  372. memerr    db    'Not enough memory','$'
  373. vgaerr    db    'VGA card not found','$'
  374. filerr    db    'File error','$'
  375. _386err    db    '386 or better required','$'
  376.  
  377. orig    db    xsize2 dup (0)
  378. dest    db    xsize2 dup (0)
  379. temp    db    xsize2 dup (0)
  380.  
  381. trans    label
  382. include transfrm.dat
  383.  
  384. inpseg        dw    0
  385. maddr        dw    0
  386. mnewaddr    dw    0
  387. TGA_filename    db    'lens.tga',0
  388. TGA_handle    dw    0
  389. ReadBuffer    db    768 dup (0)
  390.  
  391.     ends
  392.     end    start
  393.